package com.hxk.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;
/**
 * 全局异常类使用@ControllerAdvice+@ExceptionHandler实现
 * @author Cactus
 */
@ControllerAdvice
public class GlobalException {

	/**
	 * 处理系统中所有空指针异常
	 * @param e
	 * @return
	 */
	@ExceptionHandler(java.lang.NullPointerException.class)
	public ModelAndView nullException(Exception e) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("error", e.toString());
		mav.setViewName("error1");
		return mav;
	}
	/**
	 * 处理系统中所有算数异常
	 * @param e
	 * @return
	 */
	@ExceptionHandler(java.lang.ArithmeticException.class)
	public ModelAndView arithmeticException(Exception e) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("error", e.toString());
		mav.setViewName("error2");
		return mav;
	}
}
